Fix arrow function body parsing#1
Closed
DanBurton wants to merge 3 commits into
Closed
Conversation
We add three failing tests:
1. {()=>{};``}
2. {x=>x;``}
3. {f:x=>x,y:2}
We also add a fourth test mirroring the third but with a function block
body instead of an expression. The hope is that we get no regressions
when we change the representation of arrow functions.
The issue with the current parsing rules and representation is that arrow function bodies are not statements, they're either function blocks or expressions. Looking at the specification (https://www.ecma-international.org/ecma-262/#prod-ExpressionBody) we see that the expressions are `AssignmentExpression` in particular. Making this change appears to fix the additional tests, but it breaks minification.
The minifier was treating arrow functions with block bodies incorrectly
if they contained a single expression statement with no return
statement. It was transforming them into arrow functions with expression
bodies.
This means for instance that in
```js
let x = (() => { 42 })();
```
`x` would equal `undefined` before minification, but would equal `42`
after minification. The fix is to change the tests to match the correct
behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See: quintenkasteel#117